package com.briup.sms.service.impl;

import com.briup.sms.dao.CategoryMapper;
import com.briup.sms.dao.OrderMapper;
import com.briup.sms.dao.ShopMapper;
import com.briup.sms.dao.UserMapper;
import com.briup.sms.entity.CategoryGender;
import com.briup.sms.entity.CategoryStats;
import com.briup.sms.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author :xuyang
 * @DateTime:2024/1/11 10:51
 * @Version :v1.0.0
 * ClassName:DashboardServiceImpl
 * Package  :com.briup.sms.service.impl
 * Description:TODO
 */
@Service
public class DashboardServiceImpl implements DashboardService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    ShopMapper shopMapper;
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    CategoryMapper categoryMapper;

    @Override
    public Map map() {
        HashMap<Object, Object> map = new HashMap<>();
        Integer user = userMapper.countUser();
        Integer shop = shopMapper.countShop();
        Integer order = orderMapper.countOrder();
        Integer category = categoryMapper.countCategory();
        map.put("userNum", user);
        map.put("shopNum", shop);
        map.put("orderNum", order);
        map.put("categoryNum", category);
        return map;
    }

    @Override
    public Map sexRatio() {
        HashMap<String, Object> map = new HashMap<>();
        List<CategoryGender> genders = userMapper.countGender();
        for (CategoryGender gender : genders) {
            Double man = gender.getMan();
            Double woman = gender.getWoman();
            Double donnot = gender.getDonnot();
            map.put("男", man);
            map.put("女", woman);
            map.put("未知", donnot);
        }
        return map;
    }

    @Override
    public Map categoryStats() {
        HashMap<Object, Object> map = new HashMap<>();
        List<CategoryStats> list = categoryMapper.categoryStats();
        for (CategoryStats o : list) {
            String name = o.getName();
            Integer num = o.getNum();
            map.put(name, num);
        }
        return map;
    }
}

